<template>
<div class="layout-route">
    <div class="card card-search">
        <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="100px">
            <el-form-item label="分区名称" prop="name">
                <el-input v-model.trim="queryParams.name" placeholder="请输入分区名称" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="">
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
    </div>

    <div class="card">
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" @click="showDetailDialog({}, 'add')">添加</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="tableData" border script>
            <el-table-column label="序号" prop="id" min-width="100" show-overflow-tooltip></el-table-column>
            <el-table-column label="分区名称" prop="name" min-width="160" show-overflow-tooltip></el-table-column>
            <el-table-column label="拥有货架数" prop="NumberOfShelvesOwned" min-width="160" show-overflow-tooltip></el-table-column>
            <el-table-column label="分区类型" prop="type" min-width="160" show-overflow-tooltip></el-table-column>
            <el-table-column label="状态" prop="status" min-width="160" show-overflow-tooltip></el-table-column>
            <el-table-column label="操作" min-width="100">
                <template slot-scope="scope">
                    <el-button type="text" icon="el-icon-edit" @click="showDetailDialog(scope.row, 'edit')">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList"></pagination>

        <DetailDialog v-model="detailDialog.visible" v-if="detailDialog.visible" :params="detailDialog.data" :type="detailDialog.type"  @success="handleQuery"></DetailDialog>

    </div>
</div>
</template>

<script>
import { getPartitionList} from '@/api/warehouse'
import DetailDialog from './components/DetailDialog.vue'
export default {
name: 'getPartitionList',
components: { DetailDialog },
data() {
    return {
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 表格数据
        tableData: [],
        arrivalStatus: [],
        deliveryStatus: [],
        pageInfo: {
            page: 1,
            limit: 10,
        },
        // 查询参数
        queryParams: {
            name: undefined,
            contract_number: undefined,
            store_time: undefined
        },
        detailDialog: {
            visible: false,
            data: {},
            type: 'add'
        },
    }
},
created() {
    this.getList()
},
methods: {
    //列表
    getList() {
        this.loading = true
        const qyparams = {
            ...this.pageInfo,
            ...this.queryParams,
        }
        getPartitionList(qyparams)
            .then(response => {
                this.tableData = response.data.list
                this.total = response.data.total
            })
            .finally(() => {
                this.loading = false
            })
    },

    // 搜索按钮操作
    handleQuery() {
        this.pageInfo.page = 1
        this.getList()
    },

    // 重置按钮操作
    resetQuery() {
        this.resetForm('queryForm')

        this.handleQuery()
    },
    showDetailDialog(row, type) {
        this.detailDialog.visible = true
        this.detailDialog.data = row
        this.detailDialog.type = type
    },
},
}
</script>
